<template>
    <!-- 公共组件 -->
    <GoodList :list="goodsList"></GoodList>
</template>

<script setup lang="ts">
import { ref, onMounted, type Ref } from 'vue'
import { RequestSearchList } from '@/api/search'
import type { IGoods } from '@/types/types'
import { useSearchStore } from '@/stores/search'
import GoodList from '@/components/GoodList.vue'
import axios from 'axios'

const useSearch = useSearchStore()

// 搜索列表
const goodsList: Ref<Array<IGoods>> = ref([])
// 获取搜索列表
const getSearchList = async () => {
    console.log(`useSearch.searchData>>>`,useSearch.searchData);
    
    const res = await axios({
        method: 'get',
        url: 'http://localhost:3000/goods/list',
        //post请求参数使用data选项, get参数 params选项
        params: {
            name:useSearch.searchData,
            // shop:this.product.shop,
            // startPrice:this.product.startPrice,
            // endPrice:this.product.endPrice,
        }
    })
    const { code, info } = res.data
    if (code === 1) {
        console.log(`info.list>>>`,info.list);
        
        goodsList.value = info.list
    }
    // const data = await RequestSearchList(useSearch.searchData)
    // const { resultCode, resultInfo } = data
    // if (resultCode === 1) {
    //     goodsList.value = resultInfo.list
    // }
}

onMounted(() => {
    getSearchList()
})
</script>

<style lang="scss" scoped>
// 商品列表
.rightcol {
    width: 100%;
    padding-left: 12px; 
    .van-card {
        width: 100%;
        .van-button {
            background-color: rgb(236, 13, 13);
            color: #fff;
            border-radius: 16px;
        }
    }
}
</style>
